package com.eupmt.lab3.controllers.impl;

import com.eupmt.lab3.controllers.IArticleController;
import com.eupmt.lab3.domain.Article;
import com.eupmt.lab3.persistence.ibatis.dao.ArticleDaoManager;
import com.eupmt.lab3.utils.Log;

/**
 *
 * @author Grup1 Lab3
 */
public class ArticleController implements IArticleController {

    //Atributs.
    protected static ArticleController instance = null;
    ArticleDaoManager dao = null;
    private Log log = null;

//Constructors.
    private ArticleController() {
        log = new Log();
    }

    public void saveArticle(Article article) throws Exception {
        dao = ArticleDaoManager.getInstance();
        dao.saveArticle(article);
    }

    public void insertArticle(Article a) throws Exception {
        dao = ArticleDaoManager.getInstance();
        dao.insertArticle(a);
    }

    public void updateArticle(Article a) throws Exception {
        dao = ArticleDaoManager.getInstance();
        dao.updateArticle(a);
    }

    public void deleteArticle(Article art) throws Exception {
        dao = ArticleDaoManager.getInstance();
        dao.deleteArticle(art);
    }

    public Article getArticleById(int idArticle) throws Exception {
        dao = ArticleDaoManager.getInstance();
        return dao.getArticleById(idArticle);
    }

    // Patró Singleton
    public static ArticleController getInstance() {
        if (instance == null) {
            instance = new ArticleController();
        }
        return instance;
    }
}
